<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="robots" content="all">
    <meta name="referrer" content="always">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-transform" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="applicable-device" content="pc,mobile" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="keywords" content="URL解码,URL编码,在线URL解码/编码工具">
    <meta name="description"
        content="URL解码/编码是一款对URL中文进行encodeURI编码或decodeURI解码的工具，支持encodeURIComponent编码、decodeURIComponent解码。">
    <title>URL解码 URL编码 在线URL解码/编码工具 iP138在线工具</title>
    <link rel="stylesheet" type="text/css" media="screen" href="../style/responsive.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="../style/page.css" />
    <script type="text/javascript" src="../jquery/3.6.0/jquery.min.js"></script>
</head>

<body>
    <div class="wrapper">
        <div class="container">
            <div class="content">
                <div class="mod-panel">
                    <div class="banner-outer"></div>
                    <div class="hd">
                        <h1>在线Unicode编码汉字互转工具</h1>
                    </div>
                    <div class="bd">
                        <div class="row">
                            <div class="col-md-12">
                                <form class="form-horizontal">
                                    <div class="form-group clearfix">
                                        <label class="col-md-2 control-label">中文内容：</label>
                                        <div class="col-md-8">
                                            <textarea id="input" class="form-control" style="height:150px;"></textarea>
                                        </div>
                                    </div>
                                    <div class="form-group clearfix">
                                        <div class="col-md-8 col-md-offset-2">
                                            <button id="encode" class="btn btn-primary" type="button">汉字转 Unicode 码
                                                <span>⇩</span></button>
                                            <button id="decode" class="btn btn-primary" type="button">Unicode 码转中文
                                                <span>⇧</span></button>
                                            <label id="ignoreLetter">
                                                <input type="checkbox" name="ignoreLetter" checked="true">
                                                不转换字母和数字
                                            </label>
                                        </div>
                                    </div>
                                    <div class="form-group clearfix">
                                        <label class="col-md-2 control-label">ASCII编码：</label>
                                        <div class="col-md-8">
                                            <textarea id="output" class="form-control" style="height:150px;"></textarea>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-10">
                                <div class="tips">
                                    <h4>Unicode编码说明</h4>
                                    <ul>
                                        <li>在线Unicode编码汉字互转工具是一款可以帮助你把中文转换成Unicode编码，同时也支持把Unicode编码过的还原成中文的在线小工具</li>
                                        <li>ASCII（American Standard Code for Information
                                            Interchange，美国信息交换标准代码）是基于拉丁字母的一套电脑编码系统，主要用于显示现代英语和其他西欧语言。它是现今最通用的单字节编码系统，并等同于国际标准ISO/IEC
                                            646。</li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <script type="text/javascript">
                (function () {
                    var $mod_panel = $('.mod-panel');
                    var $input = $mod_panel.find('#input');
                    var $output = $mod_panel.find('#output');
                    var $ignore = $mod_panel.find('#ignoreLetter');
                    $mod_panel.find('#encode').click(function () {
                        var character = $input.val().split('');
                        var ascii = "";
                        for (var i = 0; i < character.length; i++) {
                            var code = Number(character[i].charCodeAt(0));
                            if (!$ignore.checked || code > 127) {
                                var charAscii = code.toString(16);
                                charAscii = new String("0000").substring(charAscii.length, 4) + charAscii;
                                ascii += "\\u" + charAscii;
                            }
                            else {
                                ascii += character[i];
                            }
                        }
                        $output.val(ascii);
                    });
                    $mod_panel.find('#decode').click(function () {
                        var character = $output.val().split("\\u");
                        var native = character[0];
                        for (var i = 1; i < character.length; i++) {
                            var code = character[i];
                            native += String.fromCharCode(parseInt("0x" + code.substring(0, 4)));
                            if (code.length > 4) {
                                native += code.substring(4, code.length);
                            }
                        }
                        $input.val(native);
                    });
                })();
            </script>
        </div>
</body>

</html>